﻿using System;
using System.Collections.Generic;
using System.Web;


namespace Xmhouse.Passport
{
    /// <summary>
    ///Common 的摘要说明
    /// </summary>
    public static class Common
    {
        #region 返回当前的获得的IP
        /// <summary>
        /// 功能：获取真实IP地址
        /// 作者：RoseKing
        /// 日期：2010-3-29
        /// </summary>
        /// <returns>返回当前的获得的IP</returns>
        public static string GetRealIP()
        {
            string ip = null;
            try
            {
                HttpRequest request = HttpContext.Current.Request;

                if (request.ServerVariables["HTTP_VIA"] != null)
                {
                    if (request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
                    {
                        ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
                    }
                    else
                    {
                        ip = "127.0.0.1";
                    }
                }
                else
                {
                    ip = request.UserHostAddress;
                }
            }
            catch 
            {
                ip = "127.0.0.1";
            }
            return ip;
        }
        #endregion


    }
}